package com.cskaoyan.servlet;

import com.cskaoyan.bean.AddressParameter;
import com.cskaoyan.bean.PageData;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.common.CommonServlet;
import com.cskaoyan.service.AddressService;
import com.cskaoyan.service.impl.AddressServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

@WebServlet("/admin/address/*")
public class AdminAddressServlet extends CommonServlet {
    AddressService addressService = new AddressServiceImpl();

    public BaseRespVo list(HttpServletRequest request, HttpServletResponse response) throws InvocationTargetException, IllegalAccessException {
        Map<String, String[]> parameterMap = request.getParameterMap();
        AddressParameter addressParameter = new AddressParameter();
        BeanUtils.copyProperties(addressParameter, parameterMap);

        PageData pageData = addressService.list(addressParameter);

        return BaseRespVo.ok(pageData);
    }
}
